package com.ruoyi.web.controller.djb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.djb.domain.DjbExam;
import com.ruoyi.djb.service.IDjbExamService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审核Controller
 * 
 * @author xxd
 * @date 2024-11-05
 */
@Controller
@RequestMapping("/djb/exam")
public class DjbExamController extends BaseController
{
    private String prefix = "djb/exam";

    @Autowired
    private IDjbExamService djbExamService;

    @RequiresPermissions("djb:exam:view")
    @GetMapping()
    public String exam()
    {
        return prefix + "/exam";
    }

    /**
     * 查询审核列表
     */
    @RequiresPermissions("djb:exam:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbExam djbExam)
    {
        startPage();
        List<DjbExam> list = djbExamService.selectDjbExamList(djbExam);
        return getDataTable(list);
    }

    /**
     * 导出审核列表
     */
    @RequiresPermissions("djb:exam:export")
    @Log(title = "审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbExam djbExam)
    {
        List<DjbExam> list = djbExamService.selectDjbExamList(djbExam);
        ExcelUtil<DjbExam> util = new ExcelUtil<DjbExam>(DjbExam.class);
        return util.exportExcel(list, "审核数据");
    }

    /**
     * 新增审核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存审核
     */
    @RequiresPermissions("djb:exam:add")
    @Log(title = "审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbExam djbExam)
    {
        return toAjax(djbExamService.insertDjbExam(djbExam));
    }

    /**
     * 修改审核
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbExam djbExam = djbExamService.selectDjbExamById(id);
        mmap.put("djbExam", djbExam);
        return prefix + "/edit";
    }

    /**
     * 修改保存审核
     */
    @RequiresPermissions("djb:exam:edit")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbExam djbExam)
    {
        return toAjax(djbExamService.updateDjbExam(djbExam));
    }

    /**
     * 删除审核
     */
    @RequiresPermissions("djb:exam:remove")
    @Log(title = "审核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbExamService.deleteDjbExamByIds(ids));
    }
}
